
Partial Class Case_caseProgramInfo
    Inherits System.Web.UI.UserControl
    Implements IPermission

    Public ReadOnly Property SectionName() As String Implements IPermission.SectionName
        Get
            Return "Program Info"
        End Get
    End Property

    Public ReadOnly Property ControlCollection() As System.Web.UI.ControlCollection Implements IPermission.ControlCollection
        Get
            Return Me.Controls
        End Get
    End Property

    Public ReadOnly Property EntityPermissionType() As Cdm.DataCore.UserSecurity.Permission.PermissionType Implements IPermission.EntityPermissionType
        Get
            Return Cdm.DataCore.UserSecurity.Permission.PermissionType.CaseProgramInfo
        End Get
    End Property

    Public Property PrimaryObject() As Cdm.DataCore.ConfigurableObject Implements IPermission.PrimaryObject
        Get
            Dim pg As IPermission = Me.Page
            Return pg.PrimaryObject
        End Get
        Set(ByVal value As Cdm.DataCore.ConfigurableObject)
            EntityController.SetPagePropertiesFromObject(Me, True, "ProgramInfo")
            Dim pt As Cdm.DataCore.Entities.Participant = CType(value, Cdm.DataCore.Entities.Participant)
            Me.SpecialFieldProgramInfo.Editable = CheckEditable()
            Me.SpecialFieldProgramInfo.PrimaryObject = pt.ProgramInfoSpecialFields
            ShowDates()
        End Set

        
    End Property

    Private Function CheckEditable() As Boolean
        If Me.PrimaryObject.Id > 0 Then
            Return UserAuthorization.HasUpdatePermission(Me.EntityPermissionType)
        Else
            Return UserAuthorization.HasInsertPermission(Me.EntityPermissionType)
        End If

    End Function

    Public Sub ResetControls() Implements IPermission.ResetControls

    End Sub

    Public Sub ShowDates()

        Dim pt As Cdm.DataCore.Entities.Participant = Me.PrimaryObject
        Me.NextAssessmentDateLabel.Text = pt.NextAssessment(Convert.ToInt32(Application("AssessmentFrequency")))
        Me.NextInPersonMonitoringDateLabel.Text = pt.NextMonitoring(Convert.ToInt32(Application("InPersonMonitoringFrequency")))

    End Sub

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

        Me.DateOfLastAssessmentInputControl.Enabled = (ConfigurationManager.AppSettings("AssessmentsUrl") Is Nothing)

        If Me.IsPostBack Then
            EntityController.SetPagePropertiesFromObject(Me, False, "ProgramInfo")
            Dim pt As Cdm.DataCore.Entities.Participant = Me.PrimaryObject
            Me.SpecialFieldProgramInfo.Editable = CheckEditable()
            Me.SpecialFieldProgramInfo.PrimaryObject = pt.ProgramInfoSpecialFields

        Else
            BindDropDowns()
        End If

    End Sub

    Public Sub SaveData()
        EntityController.SetObjectPropertiesFromPage(Me)
        Dim pt As Cdm.DataCore.Entities.Participant = Me.PrimaryObject
        Dim programInfoSpecialFields As Cdm.DataCore.Entities.ProgramInfo = pt.ProgramInfoSpecialFields
        programInfoSpecialFields.SpecialFieldsValues = Me.SpecialFieldProgramInfo.SaveSpecialFields()
    End Sub



    Private Sub BindDropDowns()

        Me.SourceOfEnrollmentInputControl.DataSource = Cdm.DataCore.LookupTables.LuSourceOfEnrollment.ListAll(0, "Select Enrollment Source")
        Me.SourceOfEnrollmentInputControl.DataTextField = "Description"
        Me.SourceOfEnrollmentInputControl.DataValueField = "Id"
        Me.SourceOfEnrollmentInputControl.DataBind()


    End Sub

End Class
